package com.ysxsoft.wdg.adapter.my;


import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.AddressBean;

public class AddressAdapter extends BaseQuickAdapter<AddressBean, BaseViewHolder> {

    public AddressAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void clear() {
        getData().clear();
        notifyDataSetChanged();
    }


    @Override
    protected void convert(BaseViewHolder helper, AddressBean item) {
        final int position = helper.getLayoutPosition();

        helper.setText(R.id.tv_address_name,item.getName());
        helper.setText(R.id.tv_address_tel,item.getPhone());
        helper.setText(R.id.tv_address_location,"收货地址："+item.getProvince()+item.getCity()+item.getCounty()+item.getAddress());

        ImageView ivSelect = helper.getView(R.id.iv_select);
        ImageView ivEdit = helper.getView(R.id.iv_address_edit);
        ImageView ivDel = helper.getView(R.id.iv_address_del);

        ivSelect.setSelected(item.getStatus() == 1);

        ivDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onAddressEditListener.onDelAddress(position);
            }
        });
        ivEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onAddressEditListener.onEditAddress(position);
            }
        });
        ivSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onAddressEditListener.onSetMoren(position);
            }
        });
    }

    public interface OnAddressEditListener{
        void onDelAddress(int position);
        void onEditAddress(int position);
        void onSetMoren(int position);
    }

    private OnAddressEditListener onAddressEditListener;
    public void setOnAddressEditListener(OnAddressEditListener onAddressEditListener){
        this.onAddressEditListener = onAddressEditListener;
    }
}
